package com.stefanini.pe.bbva.bp.in.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import com.stefanini.pe.bbva.bp.in.utils.Util;


@FacesConverter(value="fechaConverte")
public class FechaConverter implements Converter{

	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		return null;
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2){
		String fecha="";
		try {
			String arg2s = Util.getStringF((String)arg2).trim();
			if(arg2s.length()==8){
				fecha = arg2s.substring(6,8)+"/"+arg2s.substring(4,6)+"/"+arg2s.substring(0,4);
			}else{
				fecha = arg2s;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fecha;		
	}
}
